package com.zzq.base.awesome.controller;

import com.zzq.base.awesome.entity.CommonData;
import com.zzq.base.awesome.entity.Result;
import com.zzq.base.awesome.entity.SingleObject;
import com.zzq.base.awesome.utils.FileUtils;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Date;

@RestController
@RequestMapping("/upload")
public class FileController {

    @PostMapping()
    public Result<String> avatar(@RequestParam(value = "file") MultipartFile file) throws Exception {
        String path = SingleObject.dataOfFile.format(new Date()) + CommonData.LINUXFILEPATHSPLITE
                + FileUtils.getFileName(file.getOriginalFilename());
        if (FileUtils.saveFile(SingleObject.filePath + path, file)) {
            return Result.buildSuccess(path);
        }else {
            return Result.buildSaveFileError();
        }

    }
}
